package com.java.comprehensive;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.Week;
import cn.hutool.poi.excel.BigExcelWriter;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import org.junit.jupiter.api.Test;

import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.concurrent.*;

public class Main {
    public static ExecutorService executorPool = null;

    public static void main(String[] args) throws InterruptedException, ExecutionException {
        ExecutorService executor = Executors.newFixedThreadPool(2);
        final String[] a = {"空字符串"};
        //创建一个Callable，3秒后返回String类型
        Callable myCallable = new Callable() {
            @Override
            public String call() throws Exception {
//                Thread.sleep(3000);
                a[0] = "他不等于空了";
                System.out.println("calld方法执行了");
                return "call方法返回值";
            }
        };
        System.out.println("提交任务之前 "+getStringDate());
        Future future = executor.submit(myCallable);
        System.out.println("提交任务之后，获取结果之前 "+getStringDate());
        System.out.println("获取返回值: "+future.get());
        System.out.println("a:" + Arrays.toString(a));
        System.out.println("获取到结果之后 "+getStringDate());
    }
    public static String getStringDate() {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
        String dateString = formatter.format(currentTime);
        return dateString;

    }

    @Test
    public void bloomFiter(){
        List<?> row1 = CollUtil.newArrayList("aa", "bb", "cc", "dd", DateUtil.date(), 3.22676575765);
        List<?> row2 = CollUtil.newArrayList("aa1", "bb1", "cc1", "dd1", DateUtil.date(), 250.7676);
        List<?> row3 = CollUtil.newArrayList("aa2", "bb2", "cc2", "dd2", DateUtil.date(), 0.111);
        List<?> row4 = CollUtil.newArrayList("aa3", "bb3", "cc3", "dd3", DateUtil.date(), 35);
        List<?> row5 = CollUtil.newArrayList("aa4", "bb4", "cc4", "dd4", DateUtil.date(), 28.00);

        List<List<?>> rows = CollUtil.newArrayList(row1, row2, row3, row4, row5);

        BigExcelWriter writer= ExcelUtil.getBigWriter("e:/xxx.xlsx");
        // 一次性写出内容，使用默认样式
        writer.write(rows);
        // 关闭writer，释放内存
        writer.close();

    }
    @Test
    public void test2(){
        List<String> row1 = CollUtil.newArrayList("aa", "bb", "cc", "dd");
        List<String> row2 = CollUtil.newArrayList("aa1", "bb1", "cc1", "dd1");
        List<String> row3 = CollUtil.newArrayList("aa2", "bb2", "cc2", "dd2");
        List<String> row4 = CollUtil.newArrayList("aa3", "bb3", "cc3", "dd3");
        List<String> row5 = CollUtil.newArrayList("aa4", "bb4", "cc4", "dd4");
        List<List<String>> rows = CollUtil.newArrayList(row1, row2, row3, row4, row5);
        //通过工具类创建writer
        ExcelWriter writer = ExcelUtil.getWriter("d:/writeTest.xlsx");
        //通过构造方法创建writer
        //ExcelWriter writer = new ExcelWriter("d:/writeTest.xls");
        //跳过当前行，既第一行，非必须，在此演示用
        writer.passCurrentRow();
        //合并单元格后的标题行，使用默认标题样式
//        writer.merge(list1.size() - 1, "测试标题");
        //一次性写出内容，强制输出标题
        writer.write(rows, true);
        //关闭writer，释放内存
        writer.close();
    }

    @Test
    public void test3(){
        String nowDay = DateUtil.format(new Date(),"yyyy-MM-dd");
        Week week = DateUtil.dayOfWeekEnum(new Date());
        String yuandanjie = "2022-01-01";
        String yuandan  = DateUtil.formatBetween(new Date(),DateUtil.parse(yuandanjie));
        String chunjie = "2022-02-01";
        String chunjieTime  = DateUtil.formatBetween(new Date(),DateUtil.parse(chunjie));
        //今天周几
        int value = week.getValue();
        int weekDay = 5+1 - value;
        String time = "【摸鱼办】提醒您：\n" + nowDay +"下午好，摸鱼人！\n今天是" +nowDay+ "工作再累，一定不要忘记摸鱼哦！\n" + "有事没事起身去茶水间，去厕所，去廊道走走\n"
            + "别老在工位上坐着，钱是老板的,但命是自己的\n" + "距离周末假期还有"+weekDay+"\n" + "距离元旦假期还有"+yuandan+"\n" + "距离春节假期还有"+chunjieTime+"\n" + "上班是帮老板赚钱，摸鱼是赚老板的钱！\n"
            + "最后，祝愿天下所有摸鱼人，都能愉快的渡过每一天…";
        System.out.println(time);
    }

    @Test
	public void test4(){
		String str_ = "Hello Riley James~";
		ByteBuffer wrap = ByteBuffer.wrap(str_.getBytes());
		System.out.println(new String(wrap.array()));
	}
}